import request from '@/utils/request'
import { HTTP_METHOD } from '@/utils/const/http/method'

const baseUrl = '/auth/cms/release/'

/**
 * 查询数据
 *
 * @param params {object} 查询参数
 * @return Page<CmsPage>
 */
export function select (params) {
  return request({
    url: baseUrl,
    method: HTTP_METHOD.GET,
    params
  })
}

/**
 * 获取发布资源
 *
 * @return List<JsTree>
 */
export function selectAssets () {
  return request({
    url: `${baseUrl}assets`,
    method: HTTP_METHOD.GET
  })
}

/**
 * 保存
 *
 * @param params {object} 表单数据
 * @return CmsPage
 */
export function saveRelease (params) {
  return request({
    url: baseUrl,
    method: HTTP_METHOD.POST,
    data: params
  })
}

/**
 * 开始发布
 *
 * @param id id
 * @return true/false
 */
export function startRelease (id) {
  return request({
    url: `${baseUrl}start/${id}`,
    method: HTTP_METHOD.POST
  })
}

/**
 * 取消发布
 *
 * @param id id
 * @return true/false
 */
export function cancelRelease (id) {
  return request({
    url: `${baseUrl}cancel/${id}`,
    method: HTTP_METHOD.POST
  })
}

/**
 * 获取已发布数量
 *
 * @param id id
 * @return 数量
 */
export function getReleaseProgress (id) {
  return request({
    url: `${baseUrl}progress/${id}`,
    method: HTTP_METHOD.GET
  })
}

/**
 * 发布单个列队数据
 *
 * @param id    id
 * @return true/false
 */
export function releaseQueue (id) {
  return request({
    url: `${baseUrl}release/queue/${id}`,
    method: HTTP_METHOD.POST
  })
}
